//
//  AppDelegate.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/7.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//appdelegate
#import "AppDelegate.h"
#import <AlipaySDK/AlipaySDK.h>
#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "HomeViewController.h"
//#import "ExhibitionListViewController.h"
#import "ExhibitionViewController.h"
//
#import "ServiceViewController.h"
#import "DiscoverViewController.h"
#import "DiscoverHouseholdListViewController.h"
#import "MyViewController.h"
#import "HAODEsingleton.h"
#import "UMSocial.h"
#import "httpRequest.h"
#import "ScanViewController.h"
#import "UMSocialWechatHandler.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
{
    HAODEsingleton* commdity;
//    MAMapView *myMV;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
//–inserta delay of 5 seconds before the splash screendisappears–
//    [NSThread sleepForTimeInterval:0.];
//Override point for customization after applicationlaunch.
//Add the view controller’s view to the window anddisplay.
   commdity=[HAODEsingleton shared];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self setupViewControllers];
    [self.window setRootViewController:self.viewController];
    [self.window makeKeyAndVisible];
    
    [[UINavigationBar appearance] setBarTintColor:Color];
    [self customizeInterface];
    
//  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
//  [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    [[UITextField appearance] setTintColor:luseColor];
//  [[UILabel appearance] setFont:[UIFont fontWithName:@"STHeitiSC-Light" size:14]];
    

   
//  [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    [UMSocialData setAppKey:@"564c046767e58eba1300118e"];
    [[UIApplication sharedApplication]
     canOpenURL:[NSURL URLWithString:@"weixin(微信)://"]];
    [UMSocialWechatHandler setWXAppId:@"wx024fe293a9460a42" appSecret:@"d4624c36b6795d1d99dcf0547af5443d" url:@"http://www.honglinkTech.com"];
 
    //[UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];
//    [UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
//    
//    //打开新浪微博的SSO开关，设置新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。若在新浪后台设置我们的回调地址，“http://sns.whalecloud.com/sina2/callback”，这里可以传nil ,需要 #import "UMSocialSinaHandler.h"
//    [UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    
       
   
    return YES;
}


#pragma mark - Methods

- (void)setupViewControllers {

//    
    UIViewController *secondViewController = [[MyViewController alloc] init];
    UIViewController *MyNavigationController = [[UINavigationController alloc]
                                                    initWithRootViewController:secondViewController];
//
    UIViewController *thirdViewController = [[DiscoverHouseholdListViewController alloc] init];
    UIViewController *DiscoverNavigationController = [[UINavigationController alloc]
                                                   initWithRootViewController:thirdViewController];
    
    
    
    
    UIViewController *centerViewController = [[ScanViewController alloc] init];
    UIViewController *centerNavigationController11 = [[UINavigationController alloc]
                                                  initWithRootViewController:centerViewController];
    
    
    UIViewController *ViViewController = [[ExhibitionViewController alloc] init];
    UIViewController *ServiceNavigationController = [[UINavigationController alloc]
                                                initWithRootViewController:ViViewController];
   
    UIViewController *ViewController11 = [[HomeViewController alloc] init];
    UIViewController *RDNavigationController11 = [[UINavigationController alloc]
                                                  initWithRootViewController:ViewController11];
    
    
    RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
        [tabBarController setViewControllers:@[RDNavigationController11,ServiceNavigationController,centerNavigationController11,DiscoverNavigationController,MyNavigationController]];
//  [tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,RDNavigationController11,
//                                           thirdNavigationController,RDNavigationController]];
    self.viewController = tabBarController;
    
    [self customizeTabBarForController1:tabBarController];
}

- (void)customizeTabBarForController1:(RDVTabBarController *)tabBarController {
    //    UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
    //    UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
   
    NSArray *tabBarItemImages = @[@"shouye",@"zhanting",@"saoyisao",@"faxian",@"wode"];
    
    NSInteger index = 0;
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
        
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_hight",
                                                      [tabBarItemImages objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",
                                                        [tabBarItemImages objectAtIndex:index]]];
        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        
        index++;
    }
}

- (void)customizeInterface {
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    
    UIImage *backgroundImage =nil;
    NSDictionary *textAttributes = nil;
    
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        backgroundImage = nil;
        
        textAttributes = @{
                           NSFontAttributeName: [UIFont boldSystemFontOfSize:16],
                           NSForegroundColorAttributeName: [UIColor blackColor],
                           };
        
        
    } else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
        backgroundImage =nil;
        
        textAttributes = @{
                           UITextAttributeFont: [UIFont boldSystemFontOfSize:16],
                           UITextAttributeTextColor: [UIColor blackColor],
                           UITextAttributeTextShadowColor: [UIColor clearColor],
                           UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
                           };
#endif
    }
    
    [navigationBarAppearance setBackgroundImage:backgroundImage
                                  forBarMetrics:UIBarMetricsDefault];
    [navigationBarAppearance setTitleTextAttributes:textAttributes];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return  [UMSocialSnsService handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url];
}

//-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
//updatingLocation:(BOOL)updatingLocation
//{
//    
//    //    shareInfo.coordinate = userLocation.coordinate;
//    commdity.latitude=[NSString stringWithFormat:@"%f",  userLocation.coordinate.latitude];
//    commdity.longitude=[NSString stringWithFormat:@"%f",  userLocation.coordinate.longitude];
//    //取出当前位置的坐标
//    NSLog(@"latitude : %f,longitude: %f",userLocation.coordinate.latitude,userLocation.coordinate.longitude);
//    myMV.showsUserLocation = NO;
//}

- (void)applicationWillResignActive:(UIApplication *)application {
    
 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
   
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    [user removeObjectForKey:@"daogou"];
    
    
    [user synchronize];

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
